package net.lab1024.sa.base.config;
import org.springframework.stereotype.Component;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class CacheData<K, V> {
    // 使用线程安全的 ConcurrentHashMap作为存储
    private final Map<K, V> cacheMap = new ConcurrentHashMap<>();

    public void put(K key, V value) {
        cacheMap.put(key, value);
    }

    public V get(K key) {
        return cacheMap.get(key);
    }

    public V remove(K key) {
        return cacheMap.remove(key);
    }

    public void clear() {
        cacheMap.clear();
    }

    public int size() {
        return cacheMap.size();
    }

    public boolean containsKey(K key) {
        return cacheMap.containsKey(key);
    }


    @Override
    public String toString() {
        return cacheMap.toString();
    }
}